package org.xa3apm.vote.hibernate.bean;

import java.io.Serializable;
import java.util.Collection;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.xa3apm.vote.hibernate.entities.Person;

@Stateless
public class PersonBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 729618416380193334L;
	@PersistenceContext(unitName = "vote")
	private EntityManager em;

	public Person getById(Long id) {
		return (Person) (em.createNamedQuery("Person.getById").setParameter(
				"id", id).getSingleResult());
	}

	public Collection<Person> getAll() {
		@SuppressWarnings("unchecked")
		Collection<Person> resultList = em.createNamedQuery("Person.getAll")
				.getResultList();
		return resultList;
	}

}
